﻿// <copyright file="SampledCurveDataView.cs" company="Oleg V. Polikarpotchkin">
// Copyright © 2008-2009 Oleg V. Polikarpotchkin. All Right Reserved
// </copyright>
// <author>Oleg V. Polikarpotchkin</author>
// <email>ov-p@yandex.ru</email>
// <date>2009-01-19</date>
// <summary>OpenWPFChart library. SampledCurveDataView is the CurveDataView with the PointMarker.</summary>
// <revision>$Id$</revision>

using System;
using System.Windows;
using System.Windows.Media;

namespace OpenWPFChart.Parts
{
	/// <summary>
	/// <see cref="SampledCurveDataView"/> extends the <see cref="CurveDataView"/> type with the 
	/// <see cref="IPointMarker"/> implementation.
	/// </summary>
	public class SampledCurveDataView : CurveDataView, IPointMarker
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="SampledCurveDataView"/> class.
		/// </summary>
		/// <remarks>
		/// This object default VisualCue is the <see cref="PolylineVisual"/> Type.
		/// </remarks>
		public SampledCurveDataView()
		{
			VisualCue = typeof(PolylineVisual);
		}

		#region IPointMarker implementation
		#region PointMarker
		Drawing pointMarker;
		/// <inheritdoc />
		public Drawing PointMarker
		{
			get { return pointMarker; }
			set
			{
				if (pointMarker != value)
				{
					if (pointMarker != null && !pointMarker.IsFrozen)
						pointMarker.Changed -= PointMarkerChanged;
					pointMarker = value;
					if (pointMarker != null && !pointMarker.IsFrozen)
						pointMarker.Changed += PointMarkerChanged;
					NotifyPropertyChanged("PointMarker");
				}
			}
		}

		/// <summary>
		/// PointMarker changed.
		/// </summary>
		/// <param name="sender">The sender.</param>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
		void PointMarkerChanged(object sender, EventArgs e)
		{
			NotifyPropertyChanged("PointMarker");
		}
		#endregion PointMarker

		#region PointMarkerVisible
		bool pointMarkerVisible = true;
		/// <inheritdoc />
		public bool PointMarkerVisible
		{
			get { return pointMarkerVisible; }
			set
			{
				if (pointMarkerVisible != value)
				{
					pointMarkerVisible = value;
					NotifyPropertyChanged("PointMarkerVisible");
				}
			}
		}
		#endregion PointMarkerVisible
		#endregion IPointMarker implementation

		#region ICloneable Override
		/// <summary>
		/// Creates a new object that is a copy of the current instance.
		/// </summary>
		/// <returns>
		/// A new object that is a copy of this instance.
		/// </returns>
		/// <remarks>This method is designed to provide the deep cloning facility if desired.</remarks>
		protected override object CloneInternal()
		{
			SampledCurveDataView clone = base.CloneInternal() as SampledCurveDataView;
			// PointMarker.
			if (pointMarker != null)
			{
				clone.pointMarker = pointMarker.Clone();
				clone.pointMarker.Changed += clone.PointMarkerChanged;
			}
			return clone;
		}
		#endregion ICloneable Override
	}
}
